package cn.tedu.knows.portal.mapper;

import cn.tedu.knows.portal.model.Question;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* <p>
    *  Mapper 接口
    * </p>
*
* @author tedu.cn
* @since 2021-10-27
*/
    @Repository
    public interface QuestionMapper extends BaseMapper<Question> {

        @Select("select * from question where public_status = 1 order by page_views desc limit 0,10")
        List<Question> findHotQuestions();

        @Select("select count(*) from question where user_id = #{id}")
        int countQuestionsById(int id);

        @Select("select count(*) from user_collect where user_id=#{id}")
       int countCollectById(int id );
        @Select("SELECT q.*\n" +
                "FROM question q LEFT join user_question uq \n" +
                "ON q.id=uq.question_id\n" +
                "WHERE uq.user_id=#{id} OR q.user_id=#{id}\n" +
                "ORDER BY q.createtime DESC")
        List<Question> findTeacherQuestions(Integer userId);
    }
